<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Router
 *
 * @author Kamdem Kenmogne 
 */
class Router {
    
    private $app;
    
    public function __construct($app)
    {
        $this->app = $app;
    }
    
    /**
     * 
     * @param type $method
     * @param type $url
     * @param type $action
     * @return type
     */
    public function call($method, $url, $action)
    {
        return $this->app->$method($url, function() use ($action)
        {
            $action = explode('/', $action);
            $controller_name = $action[0] ;//. 'Controller';
            $method = $action[1];
            $controller = new $controller_name($this->app);
            call_user_func_array([$controller, $method], func_get_args());
        });
    }
    
    public function post($url, $action)
    {
        return $this->call('post',$url, $action);
    }
    
    public function get($url, $action)
    {
        return $this->call('get',$url, $action);
    }
    
    public function put($url, $action)
    {
        return $this->call('put',$url, $action);
    }
    
    public function delete($url, $action)
    {
        return $this->call('delete',$url, $action);
    }
}
